package com.dianwang.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Processor {
    DefectMatcherAdvanced defectMatcher;

    public static Map<String, String> entityMap = new HashMap<>();

    static {
        // 通过加载同义词文件或使用已有的 SYNONYM_MAP
        // 这里假设我们从 TextPreprocessor 的 SYNONYM_MAP 中获取同义词
        // 这样可以保持一致性
        entityMap.putAll(TextPreprocessor.SYNONYM_MAP);

        // 其他特定的实体替换
        entityMap.put("温", "测温装置");
        entityMap.put("温度异常", "测温装置");
        entityMap.put("温度发热", "测温装置");
        entityMap.put("温差", "测温装置");

        // 渗油与漏油相关
        entityMap.put("低", "少");
        entityMap.put("高", "多");
        entityMap.put("冷却", "冷却器");
    }

    public Processor(DefectMatcherAdvanced defectMatcher) {
        this.defectMatcher = defectMatcher;
    }

    /**
     * 处理输入文本，应用实体替换。
     *
     * @param input 输入文本
     * @return 替换后的文本
     */
    public String preprocess(String input) {
        StringBuilder sb = new StringBuilder(input);
        for (String key : entityMap.keySet()) {
            if (input.contains(key)) {
                sb.append(" ").append(entityMap.get(key));
            }
        }
        return sb.toString();
    }

    public void process(String input) {
        String preprocessed = TextPreprocessor.preprocess(input);
        EntityRecognizer.Entities entities = EntityRecognizer.recognizeEntities(preprocessed);

        System.out.println("输入句子: " + input);
        System.out.println("变电站名称: " + entities.substation);
        System.out.println("设备名称: " + (entities.equipment != null ? entities.equipment : "未识别"));
        System.out.println("-----------------------------------");
    }
}
